package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmOrderCollectDetails;
import com.ruoyi.crm.service.ICrmOrderCollectDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机收款详情Controller
 *
 * @author yanwenliang
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/crm/collectDetails")
public class CrmOrderCollectDetailsController extends BaseController
{
    @Autowired
    private ICrmOrderCollectDetailsService crmOrderCollectDetailsService;

    /**
     * 查询商机收款详情列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:collectDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmOrderCollectDetails crmOrderCollectDetails)
    {
        startPage();
        List<CrmOrderCollectDetails> list = crmOrderCollectDetailsService.selectCrmOrderCollectDetailsList(crmOrderCollectDetails);
        return getDataTable(list);
    }

    /**
     * 导出商机收款详情列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:collectDetails:export')")
    @Log(title = "商机收款详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmOrderCollectDetails crmOrderCollectDetails)
    {
        List<CrmOrderCollectDetails> list = crmOrderCollectDetailsService.selectCrmOrderCollectDetailsList(crmOrderCollectDetails);
        ExcelUtil<CrmOrderCollectDetails> util = new ExcelUtil<CrmOrderCollectDetails>(CrmOrderCollectDetails.class);
        util.exportExcel(response, list, "商机收款详情数据");
    }

    /**
     * 获取商机收款详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('crm:collectDetails:query')")
    @GetMapping(value = "/{collectDetailsId}")
    public AjaxResult getInfo(@PathVariable("collectDetailsId") String collectDetailsId)
    {
        return success(crmOrderCollectDetailsService.selectCrmOrderCollectDetailsByCollectDetailsId(collectDetailsId));
    }

    /**
     * 新增商机收款详情
     */
//    @PreAuthorize("@ss.hasPermi('crm:collectDetails:add')")
    @Log(title = "商机收款详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmOrderCollectDetails crmOrderCollectDetails)
    {
        return toAjax(crmOrderCollectDetailsService.insertCrmOrderCollectDetails(crmOrderCollectDetails));
    }

    /**
     * 修改商机收款详情
     */
//    @PreAuthorize("@ss.hasPermi('crm:collectDetails:edit')")
    @Log(title = "商机收款详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmOrderCollectDetails crmOrderCollectDetails)
    {
        return toAjax(crmOrderCollectDetailsService.updateCrmOrderCollectDetails(crmOrderCollectDetails));
    }

    /**
     * 删除商机收款详情
     */
//    @PreAuthorize("@ss.hasPermi('crm:collectDetails:remove')")
    @Log(title = "商机收款详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectDetailsIds}")
    public AjaxResult remove(@PathVariable String[] collectDetailsIds)
    {
        return toAjax(crmOrderCollectDetailsService.deleteCrmOrderCollectDetailsByCollectDetailsIds(collectDetailsIds));
    }
}
